package com.briup.app02.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import com.briup.app02.bean.OrderComment;
import com.briup.app02.bean.extend.OrderCommentExtend;
import com.briup.app02.service.IOrderCommentService;
import com.briup.app02.utils.Message;
import com.briup.app02.utils.MessageUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/ordercomment")
@Api(description = "jz-订单评论管理")
public class OrderCommentController {

	@Autowired
	private IOrderCommentService orderCommentService;
	
	@ApiOperation(value = "根据id删除评论")
    @ApiImplicitParams({
        @ApiImplicitParam(name="id",value = "主键",paramType = "query", required=true),
    })
	@GetMapping("deleteById")
	public Message deleteById(Long id) {
		orderCommentService.deleteById(id);
		return MessageUtil.success("删除成功");
	}
	
	@ApiOperation(value = "评论订单")
    @ApiImplicitParams({
        @ApiImplicitParam(name="id",value = "主键",paramType = "form"),
        @ApiImplicitParam(name="content",value = "评论内容",paramType = "form",required = true),
        @ApiImplicitParam(name="commentTime",value = "评论时间",paramType = "form"),
    	@ApiImplicitParam(name="status",value = "状态",paramType = "form"),
        @ApiImplicitParam(name="orderId",value = "订单编号",paramType = "form",required = true),
        @ApiImplicitParam(name="customerId",value = "顾客编号",paramType = "form",required = true)
    })
	@PostMapping("submit")
	public Message submit(OrderComment orderComment) {
		orderCommentService.saveOrUpdate(orderComment);
		return MessageUtil.success("评论成功");
	}
	
	@ApiOperation(value = "审核通过")
    @ApiImplicitParams({
        @ApiImplicitParam(name="id",value = "主键",paramType = "query", required=true),
    })
	@PostMapping("checkPass")
	public Message checkPass(Long id) {
		orderCommentService.changeStatus(id, "通过");
		return MessageUtil.success("审核通过");
	}
	
	@ApiOperation(value = "审核不通过")
    @ApiImplicitParams({
        @ApiImplicitParam(name="id",value = "主键",paramType = "query", required=true),
    })
	@PostMapping("checkNoPass")
	public Message checkNoPass(Long id) {
		orderCommentService.changeStatus(id, "不通过");
		return MessageUtil.success("审核不通过");
	}
	
	// 分页
	@ApiOperation(value = "分页查询")
    @ApiImplicitParams({
    	@ApiImplicitParam(name="page",value = "页码",paramType = "form",required = true),
    	@ApiImplicitParam(name="pageSize",value = "每页记录数",paramType = "form",required = true),
    	@ApiImplicitParam(name="content",value = "评论内容",paramType = "form"),
    	@ApiImplicitParam(name="status",value = "状态",paramType = "form"),
        @ApiImplicitParam(name="orderId",value = "订单编号",paramType = "form")
    })
	@GetMapping("pageQuery")
	public Message pageQuery(int page, int pageSize, String content, String status, Long orderId) {
		List<OrderCommentExtend> orderCommentExtends = orderCommentService.pageQuery(page, pageSize, content, status, orderId);
		return MessageUtil.success(orderCommentExtends);
	}
	
//	@ApiOperation(value = "获取全部评论")
//	@GetMapping("findAll")
//	public Message findAll() {
//		List<OrderComment> orderComments = orderCommentService.findAll();
//		return MessageUtil.success(orderComments);
//	}
}

